const { createServer } = require('http');
const { setURL } = require('./config');
const ServerData = require('./data');

const server = createServer((req, res) => {
  req.on('data', (chunk) => {
    console.time('chunk');
    console.log('\r\n' + chunk);
    console.timeEnd('chunk');
  });

  req.on('end', () => {
    console.log('receive request end');
  });

  res.writeHead(200, {
    'Content-Type': 'text/json',
    'Access-Control-Allow-Origin': '*'
  });
  res.end();
});

server.on('connection', () => {
  console.log('connection emit');
})

server.on('request', () => {
  console.log('request emit');
});

server.on('close', () => {
  console.log('server closed!');
});

server.listen({
  hostname: URL.hostname,
  port: URL.port
});
